package app1

import app1.feign.ServiceSet1
import org.springframework.beans.factory.annotation.Autowired

class SampleApiController {
    static responseFormats = ['json', 'xml']

    @Autowired
    ServiceSet1 serviceSet1

    def serviceSet1Proxy

    def sampleApiService

    def index(String dependency) {
        def bearerToken = request.getHeader("Authorization")?.substring("Bearer ".length())//Bearer XXX-XXX-XXX-XXX

        def result = [token: bearerToken, provider: "sampleApi@app1", dependency: dependency]

        switch (dependency) {
            case "restTemplate":
                result.consumption = serviceSet1Proxy.sampleApi1(bearerToken, dependency)
                break
            case "feign":
                result.consumption = serviceSet1.sampleApi1("Bearer " + bearerToken, dependency)
                break
            default:
                result.consumption = sampleApiService.process(bearerToken, "zuul/gateway")
                break
        }

        respond result, formats: responseFormats
    }
}
